package com.gitee.neuray.security.modules.param.controller;

import java.util.Arrays;
import java.util.Map;

import com.gitee.neuray.security.common.utils.EntityUtils;
import com.gitee.neuray.security.common.validator.ValidatorUtils;
import com.gitee.neuray.security.modules.param.entity.ParamItemEntity;
import com.gitee.neuray.security.modules.param.service.ParamItemService;
import com.gitee.neuray.security.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gitee.neuray.security.common.utils.PageUtils;
import com.gitee.neuray.security.common.utils.R;



/**
 * 参数项表
 *
 * @author neuray
 * @email neuray@neuray.com
 * @date 2020-09-16 15:25:50
 */
@RestController
@RequestMapping("/param/item")
public class ParamItemController {
    @Autowired
    private ParamItemService paramItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("param:item:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = paramItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("param:item:info")
    public R info(@PathVariable("id") Long id){
        ParamItemEntity paramItem = paramItemService.getById(id);

        return R.ok().put("paramItem", paramItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("param:item:save")
    public R save(@RequestBody ParamItemEntity paramItem){

        EntityUtils.setCreatAndUpdatInfo(paramItem);

        paramItemService.save(paramItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("param:item:update")
    public R update(@RequestBody ParamItemEntity paramItem){
        ValidatorUtils.validateEntity(paramItem);
        paramItemService.updateById(paramItem);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("param:item:delete")
    public R delete(@RequestBody Long[] ids){
        paramItemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
